package com.changhai.diabetes.service.impl;

import java.util.List;

import com.changhai.diabetes.model.Bear;
import com.changhai.diabetes.model.BearForExport;
import com.changhai.diabetes.model.ConcurrentResultForExport;
import com.changhai.diabetes.model.Drug;
import com.changhai.diabetes.model.DrugTreatment;
import com.changhai.diabetes.model.DrugTreatmentForExport;
import com.changhai.diabetes.model.Family;
import com.changhai.diabetes.model.FamilyForExport;
import com.changhai.diabetes.model.InterGroupUser;
import com.changhai.diabetes.model.InterPatientGroup;
import com.changhai.diabetes.model.InterPatientUser;
import com.changhai.diabetes.model.LabPhysical;
import com.changhai.diabetes.model.LabPhysicalForExport;
import com.changhai.diabetes.model.LabSugarForExport;
import com.changhai.diabetes.model.NutritionSuifang;
import com.changhai.diabetes.model.NutritionSuifangForExport;
import com.changhai.diabetes.model.NutritionSurvey;
import com.changhai.diabetes.model.NutritionSurveyForExport;
import com.changhai.diabetes.model.NutritionTreatment;
import com.changhai.diabetes.model.NutritionTreatmentForExport;
import com.changhai.diabetes.model.Patient;
import com.changhai.diabetes.model.PatientForExport;
import com.changhai.diabetes.model.Personal;
import com.changhai.diabetes.model.PersonalForExport;
import com.changhai.diabetes.model.PhysicalSurveyResult;
import com.changhai.diabetes.model.PhysicalSurveyResultForExport;
import com.changhai.diabetes.model.QualitySurveyResult;
import com.changhai.diabetes.model.QualitySurveyResultForExport;
import com.changhai.diabetes.model.ResearchGroup;
import com.changhai.diabetes.model.ResearchGroupForExport;
import com.changhai.diabetes.model.SportsSuifang;
import com.changhai.diabetes.model.SportsSuifangForExport;
import com.changhai.diabetes.model.SportsSurvey;
import com.changhai.diabetes.model.SportsSurveyForExport;
import com.changhai.diabetes.model.SportsTreatment;
import com.changhai.diabetes.model.SportsTreatmentForExport;
import com.changhai.diabetes.model.SymptomsSurveyResult;
import com.changhai.diabetes.model.SymptomsSurveyResultForExport;
import com.changhai.diabetes.model.TableForPatient;
import com.changhai.diabetes.model.User;
import com.changhai.diabetes.service.DataService;
import com.changhai.diabetes.util.Constants;

/**
 * 数据导出导入
 * 
 * @author Andy
 * 
 */
public class DataServiceImpl extends CommonServiceImpl implements DataService {
	public List<User> getUserList(){
		List<User> userList = this.getList(Constants.DS_CHANGHAI, "user.getAllUserInfo", null);
		return userList;
	}

	public List<ResearchGroupForExport> getAllGroupList(){
		List<ResearchGroupForExport> groupList = this.getList(Constants.DS_CHANGHAI, "researchGroup.getAllGroupList", null);
		return groupList;
	}
	
	public List<ResearchGroup> getGroupListByUserId(Long userId){
		List<ResearchGroup> groupList = this.getList(Constants.DS_CHANGHAI, "researchGroup.getGroupByUserId", userId);
		return groupList;
	}
	
	public List<String> getSurveyContentByIds(String contentIds){
		List<String> nameList = this.getList(Constants.DS_CHANGHAI, "tableForPatient.getSurveyContentByIds", contentIds);
		return nameList;
	}
	
	public List<ResearchGroup> getGanyuGroupListById(Long groupId){
		List<ResearchGroup> groupList = this.getList(Constants.DS_CHANGHAI, "researchGroup.getGanyuGroupListById", groupId);
		return groupList;
	}
	
	public List<PatientForExport> getPatientListForExport(){
		List<PatientForExport> pList = this.getList(Constants.DS_CHANGHAI, "patient.getPatientListForExport", null);
		return pList;
	}

	@Override
	public void importPatient(Patient patient,InterPatientUser ipu,InterPatientGroup ipg) {
	//public void importPatient(PatientForExport patient) {
		// TODO Auto-generated method stub
		long pid=Long.parseLong(this.insertObjectID(Constants.DS_CHANGHAI, "patient.insert", patient).toString());
		if(ipu!=null){
			ipu.setPatientid(pid);
			this.insertObjectID(Constants.DS_CHANGHAI, "interPatientUser.insert", ipu);
		}
		if(ipg!=null){
			ipg.setPatientid(pid);
			this.insertObject(Constants.DS_CHANGHAI, "interPatientGroup.insert", ipg);
		}
		
		//patient.setPatientid(Long.parseLong(this.insertObjectID(Constants.DS_CHANGHAI, "patient.import", patient).toString()));
		
		
	}

	@Override
	public List<Long> gettSurveyIdsByContent(String content) {
		// TODO Auto-generated method stub
		List<Long> idList = this.getList(Constants.DS_CHANGHAI, "tableForPatient.getSurveyIdsByContent", content);
		return idList;
	}

	@Override
	public void importResearchGroup(ResearchGroup rg, InterGroupUser igu) {
		// TODO Auto-generated method stub
		long rgid=Long.parseLong(this.insertObjectID(Constants.DS_CHANGHAI, "researchGroup.insert", rg).toString());
		if(igu!=null){
			igu.setResearchgroupid(rgid);
			this.insertObjectID(Constants.DS_CHANGHAI, "interGroupUser.insert", igu);
		}
	}

	@Override
	public List<TableForPatient> getAllTbInfo() {
		// TODO Auto-generated method stub
		List<TableForPatient> list=this.getList(Constants.DS_CHANGHAI, "tableForPatient.getAllTbInfo", null);
		return list;
	}

	@Override
	public void importUser(User user, List<InterGroupUser> igus) {
		// TODO Auto-generated method stub
		long uid=Long.parseLong(this.insertObjectID(Constants.DS_CHANGHAI, "user.insert", user).toString());
		if(igus!=null){
			for(int i=0;i<igus.size();i++){
				igus.get(i).setUserid(uid);
				this.insertObjectID(Constants.DS_CHANGHAI, "interGroupUser.insert", igus.get(i));
			}
		}
	}

	@Override
	public List<PersonalForExport> getPersonalListForExport() {
		// TODO Auto-generated method stub
		List<PersonalForExport> list=this.getList(Constants.DS_CHANGHAI, "personal.getPersonalListForExport", null);
		return list;
	}

	@Override
	public List<BearForExport> getBearListForExport() {
		// TODO Auto-generated method stub
		List<BearForExport> list=this.getList(Constants.DS_CHANGHAI, "bear.getBearListForExport", null);
		return list;
	}

	@Override
	public List<FamilyForExport> getFamilyListForExport() {
		// TODO Auto-generated method stub
		List<FamilyForExport> list=this.getList(Constants.DS_CHANGHAI, "family.getFamilyListForExport", null);
		return list;
	}
	
	@Override
	public List<LabPhysicalForExport> getLabPhysicalListForExport() {
		// TODO Auto-generated method stub
		List<LabPhysicalForExport> list=this.getList(Constants.DS_CHANGHAI, "labPhysical.getLabPhysicalListForExport", null);
		return list;
	}

	@Override
	public List<NutritionSuifangForExport> getNutritionSuifangListForExport() {
		// TODO Auto-generated method stub
		List<NutritionSuifangForExport> list=this.getList(Constants.DS_CHANGHAI, "nutritionSuifang.getNutritionSuifangListForExport", null);
		return list;
	}

	@Override
	public List<NutritionSurveyForExport> getNutritionSurveyListForExport() {
		// TODO Auto-generated method stub
		List<NutritionSurveyForExport> list=this.getList(Constants.DS_CHANGHAI, "nutritionSurvey.getNutritionSurveyListForExport", null);
		return list;
	}

	@Override
	public List<NutritionTreatmentForExport> getNutritionTreatmentListForExport() {
		// TODO Auto-generated method stub
		List<NutritionTreatmentForExport> list=this.getList(Constants.DS_CHANGHAI, "nutritionTreatment.getNutritionTreatmentListForExport", null);
		return list;
	}
	
	@Override
	public List<SportsSuifangForExport> getSportsSuifangListForExport() {
		// TODO Auto-generated method stub
		List<SportsSuifangForExport> list=this.getList(Constants.DS_CHANGHAI, "sportsSuifang.getSportsSuifangListForExport", null);
		return list;
	}

	@Override
	public List<SportsSurveyForExport> getSportsSurveyListForExport() {
		// TODO Auto-generated method stub
		List<SportsSurveyForExport> list=this.getList(Constants.DS_CHANGHAI, "sportsSurvey.getSportsSurveyListForExport", null);
		return list;
	}

	@Override
	public List<SportsTreatmentForExport> getSportsTreatmentListForExport() {
		// TODO Auto-generated method stub
		List<SportsTreatmentForExport> list=this.getList(Constants.DS_CHANGHAI, "sportsTreatment.getSportsTreatmentListForExport", null);
		return list;
	}

	@Override
	public List<DrugTreatmentForExport> getDrugTreatmentListForExport() {
		// TODO Auto-generated method stub
		List<DrugTreatmentForExport> list=this.getList(Constants.DS_CHANGHAI, "drugTreatment.getDrugTreatmentListForExport", null);
		return list;
	}

	@Override
	public List<PhysicalSurveyResultForExport> getPhysicalSurveyResultListForExport() {
		// TODO Auto-generated method stub
		List<PhysicalSurveyResultForExport> list=this.getList(Constants.DS_CHANGHAI, "physicalSurveyResult.getPhysicalSurveyResultListForExport", null);
		return list;
	}

	@Override
	public List<QualitySurveyResultForExport> getQualitySurveyResultListForExport() {
		// TODO Auto-generated method stub
		List<QualitySurveyResultForExport> list=this.getList(Constants.DS_CHANGHAI, "qualitySurveyResult.getQualitySurveyResultListForExport", null);
		return list;
	}

	@Override
	public List<SymptomsSurveyResultForExport> getSymptomsSurveyResultListForExport() {
		// TODO Auto-generated method stub
		List<SymptomsSurveyResultForExport> list=this.getList(Constants.DS_CHANGHAI, "symptomsSurveyResult.getSymptomsSurveyResultListForExport", null);
		return list;
	}

	@Override
	public List<ConcurrentResultForExport> getConcurrentResultListForExport() {
		// TODO Auto-generated method stub
		List<ConcurrentResultForExport> list=this.getList(Constants.DS_CHANGHAI, "concurrentResult.getConcurrentResultListForExport", null);
		return list;
	}

	@Override
	public void importSymptomsSurveyResult(SymptomsSurveyResult rec) {
		// TODO Auto-generated method stub
		this.insertObjectID(Constants.DS_CHANGHAI, "symptomsSurveyResult.insert", rec);
	}
	
	@Override
	public void importQualitySurveyResult(QualitySurveyResult rec) {
		// TODO Auto-generated method stub
		this.insertObjectID(Constants.DS_CHANGHAI, "qualitySurveyResult.insert", rec);
	}

	@Override
	public void importPhysicalSurveyResult(PhysicalSurveyResult rec) {
		// TODO Auto-generated method stub
		this.insertObjectID(Constants.DS_CHANGHAI, "physicalSurveyResult.insert", rec);
	}

	@Override
	public List<Drug> getDrugList() {
		// TODO Auto-generated method stub
		return this.getList(Constants.DS_CHANGHAI, "drug.getAllDrugs", null);
	}

	@Override
	public void importDrugTreatment(DrugTreatment rec) {
		// TODO Auto-generated method stub
		this.insertObjectID(Constants.DS_CHANGHAI, "drugTreatment.insert", rec);
	}

	@Override
	public void importSportsSuifang(SportsSuifang rec) {
		// TODO Auto-generated method stub
		this.insertObjectID(Constants.DS_CHANGHAI, "sportsSuifang.insert", rec);
	}

	@Override
	public void importSportsSurvey(SportsSurvey rec) {
		// TODO Auto-generated method stub
		this.insertObjectID(Constants.DS_CHANGHAI, "sportsSurvey.insert", rec);
	}

	@Override
	public void importSportsTreatment(SportsTreatment rec) {
		// TODO Auto-generated method stub
		this.insertObjectID(Constants.DS_CHANGHAI, "sportsTreatment.insert", rec);
	}

	@Override
	public void importNutritionSuifang(NutritionSuifang rec) {
		// TODO Auto-generated method stub
		this.insertObjectID(Constants.DS_CHANGHAI, "nutritionSuifang.insert", rec);
	}

	@Override
	public void importNutritionSurvey(NutritionSurvey rec) {
		// TODO Auto-generated method stub
		this.insertObjectID(Constants.DS_CHANGHAI, "nutritionSurvey.insert", rec);
	}

	@Override
	public void importNutritionTreatment(NutritionTreatment rec) {
		// TODO Auto-generated method stub
		this.insertObjectID(Constants.DS_CHANGHAI, "nutritionTreatment.insert", rec);
	}

	@Override
	public void importLabPhysical(LabPhysical rec) {
		// TODO Auto-generated method stub
		this.insertObjectID(Constants.DS_CHANGHAI, "labPhysical.insert", rec);
	}

	@Override
	public void importFamily(Family rec) {
		// TODO Auto-generated method stub
		this.insertObjectID(Constants.DS_CHANGHAI, "family.insert", rec);
	}

	@Override
	public void importBear(Bear rec) {
		// TODO Auto-generated method stub
		this.insertObjectID(Constants.DS_CHANGHAI, "bear.insert", rec);
	}

	@Override
	public void importPersonal(Personal rec) {
		// TODO Auto-generated method stub
		this.insertObjectID(Constants.DS_CHANGHAI, "personal.insert", rec);
	}

	@Override
	public List<LabSugarForExport> getLabSugarListForExport() {
		// TODO Auto-generated method stub
		return this.getList(Constants.DS_CHANGHAI, "labSugar.getLabSugarResultListForExport", null);
	}
}
